﻿// =================================================================== 
// 数据访问层(GDIT.DAL)
//====================================================================
// 文件：DFiles.cs
// 项目名称：学院网站
// 创建时间：2012-08-08
// 负责人：ChenZhiGang
//引用DevExpress.Data.Filtering，DevExpress.Xpo程序集
// 程序集介绍：文件信息数据访问层
// ===================================================================
using GDIT.Model;
using DevExpress.Data.Filtering;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GDIT.Pattern;

namespace GDIT.DAL
{
    public class DFiles : IFiles
    {

        private XpoHelper.Test<Mtb_Files> userOperation = null;

        /// <summary>
        /// 新增文件对象
        /// </summary>
        /// <param name="file">需要新增的文件对象</param>
        /// <returns>1：新增成功 0：新增失败</returns>
        public int InsertFiles(Mtb_Files file)
        {
            return XpoHelper.SaveAdded(file);
        }

        /// <summary>
        /// 更新文件对象
        /// </summary>
        /// <param name="file">需要更新的文件对象</param>
        /// <returns>1：更新成功 0：更新失败</returns>
        public int UpdateFiles(Mtb_Files file)
        {
            userOperation = new XpoHelper.Test<Mtb_Files>();
            XPCollection xp = userOperation.Operation("OID", file.OID);
            foreach (Mtb_Files b in xp)
            {
                b.FileName = file.FileName;
                b.Contents = file.Contents;
                return XpoHelper.SaveModified(b);
            }
            return 0;
        }

        /// <summary>
        /// 删除文件对象
        /// </summary>
        /// <param name="file">需要删除的文件对象</param>
        /// <returns>1：删除成功 0：删除失败</returns>
        public int DeleteFiles(Mtb_Files file)
        {
            userOperation = new XpoHelper.Test<Mtb_Files>();
            return userOperation.Delete(file.OID);
        }

        /// <summary>
        /// 查询单一的文件对象
        /// </summary>
        /// <param name="file">需要查询的单一文件对象</param>
        /// <returns>单一文件对象</returns>
        public Mtb_Files SelectFileByFile(Mtb_Files file)
        {
            Mtb_Files bulletin = null;
            userOperation = new XpoHelper.Test<Mtb_Files>();
            XPCollection xp = userOperation.Operation("OID", file.OID);
            foreach (Mtb_Files b in xp)
            {
                bulletin = b;
            }
            return bulletin;
        }

        /// <summary>
        /// 返回所有的文件对象
        /// </summary>
        /// <returns></returns>
        public XPCollection SelectAllFiles()
        {
            userOperation = new XpoHelper.Test<Mtb_Files>();
            return userOperation.Operation();
        }
    }
}
